package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TSales;
import com.ruoyi.system.service.ITSalesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 * @date 2021-03-24
 */
@Controller
@RequestMapping("/system/sales")
public class TSalesController extends BaseController
{
    private String prefix = "system/sales";

    @Autowired
    private ISysUserService iSysUserService;

    @Autowired
    private ISysRoleService iSysRoleService;

    @Autowired
    private ITSalesService tSalesService;

    @GetMapping()
    public String sales(ModelMap modelMap)
    {
//        List<SysUser> sysUsers = iSysUserService.selectUserListAll();
        List<SysUser> sysRoles = iSysUserService.selectUserListAll();
        modelMap.put("sysUsers",sysRoles);
        return prefix + "/sales";
    }

    /**
     * 查询
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSales tSales)
    {
        startPage();
        List<TSales> list = tSalesService.selectTSalesList(tSales);
        return getDataTable(list);
    }

    /**
     * 导出
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSales tSales)
    {
        List<TSales> list = tSalesService.selectTSalesList(tSales);
        ExcelUtil<TSales> util = new ExcelUtil<TSales>(TSales.class);
        return util.exportExcel(list, "sales");
    }

    /**
     * 新增
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
//        List<SysRole> sysRoles = iSysRoleService.selectRoleListAll();
        List<SysUser> sysRoles = iSysUserService.selectUserListAll();
        modelMap.put("sysUsers",sysRoles);
        return prefix + "/add";
    }

    /**
     * 新增保存
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TSales tSales)
    {
        return toAjax(tSalesService.insertTSales(tSales));
    }

    /**
     * 修改
     */
    @GetMapping("/edit/{salesId}")
    public String edit(@PathVariable("salesId") Long salesId, ModelMap mmap)
    {
        List<SysUser> sysRoles = iSysUserService.selectUserListAll();
        mmap.put("sysUsers",sysRoles);
        TSales tSales = tSalesService.selectTSalesById(salesId);
        mmap.put("tSales", tSales);
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TSales tSales)
    {
        return toAjax(tSalesService.updateTSales(tSales));
    }

    /**
     * 删除
     */
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tSalesService.deleteTSalesByIds(ids));
    }
}